package cn.itcast.cd.service.impl;

import java.util.List;

import cn.itcast.cd.dao.IBaseDao;
import cn.itcast.cd.dao.IUserDao;
import cn.itcast.cd.domain.User;
import cn.itcast.cd.resultPage.ResultPage;
import cn.itcast.cd.service.ILoginService;
import cn.itcast.cd.utils.MD5;

public class LoginServiceImpl implements ILoginService {

	private IBaseDao userDao;

	public void setUserDao(IBaseDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public User getUser(String name, String password) {
		String hql = "SELECT u From User u WHERE u.name = ? AND u.password = ?";
		password = MD5.encode(password);
		Object[] params  = new Object[]{name,password};
		ResultPage rp = userDao.query(hql, params, 0, 0);
		List<User> list = rp.getResult();
		User u = null;
		if(list.size()>0){
			u = list.get(0);
		}
		return u;
	}
}
